<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .countdown {
        width: 240px;
        height: 305px;
        text-align: center;
        line-height: 1;
        color: #fff;
        background-color: brown;
        overflow: hidden;
    }

    .countdown .next {
        font-size: 16px;
        margin: 25px 0 14px;
    }

    .countdown .title {
        font-size: 33px;
    }

    .countdown .tips {
        margin-top: 80px;
        font-size: 23px;
    }

    .countdown .clock span,
    .countdown .clock i {
        display: block;
        line-height: 34px;
        font-size: 23px;
        float: left;
        text-align: center;
    }

    .countdown .clock span {
        width: 45px;
        height: 34px;
        border-radius: 2px;
        background-color: #303430;
    }

    .countdown .clock i {
        width: 20px;
        font-style: normal;
    }
</style>

<body>
    <div class="countdown">
        <p class="next">今天是2022年9月12日</p>
        <p class="title">下班倒计时</p>
        <p class="clock">
            <span id="day">00</span>
            <i>天</i>
            <span id="hour">00</span>
            <i>:</i>
            <span id="minutes">25</span>
            <i>:</i>
            <span id="scond">20</span>
        </p>
        <p class="tips">
            现在是18:30:00
        </p>
    </div>
    <script>
        let hour = document.querySelector('#hour')
        let minutes = document.querySelector('#minutes')
        let scond = document.querySelector('#scond')
        let day =document.querySelector('#day')
        let tips = document.querySelector('.tips')
        getTime()
        setInterval(getTime, 1000)
        function getTime() {
            // 获取当前时间戳
            let nowTime = +new Date()
            // console.log(nowTime);
            // 获取未来时间戳
            let futureTime = +new Date('2022-12-28 24:00:00')
            // console.log(futureTime);
            // 距离未来时间的剩余秒数(毫秒数/1000 = 秒数)
            let count = (futureTime - nowTime) / 1000
            // console.log(count);

            // d = parseInt(总秒数 / 60 / 60 / 24) //计算天数
            let d = parseInt(count / 60 / 60 / 24)
            // console.log(d);
            d = d < 10 ? '0' + d : d

            // h = parseInt(总秒数 / 60 / 60 % 24) //计算小时
            let h = parseInt(count / 60 / 60 % 24)
            h = h < 10 ? '0' + h : h

            // m = parseInt(总秒数 / 60 % 60) //计算分钟
            let m = parseInt(count / 60 % 60)
            m = m < 10 ? '0' + m : m

            // s = parseInt(总秒数 % 60) //计算当前秒数
            let s = parseInt(count % 60)
            s = s < 10 ? '0' + s : s
            if (h && m && s > 0) {
                day.innerHTML = d
                hour.innerHTML = h
                minutes.innerHTML = m
                scond.innerHTML = s
            } else {
                hour.innerHTML = minutes.innerHTML = scond.innerHTML = '00'
            }

        }
    </script>
</body>

</html>